﻿<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <title></title>
    <script src="../../Content/js/angular1.2.13.js"></script>
</head>
<body ng-app="app" ng-controller="MyController">
    <div>
        <input ng-model="to" type="email" placeholder="Recipient" />
        <br />

        
        <textarea ng-model="emailBody"></textarea>
        <pre>{{previewText}}</pre>
    </div>
    <script>
        angular.module('emailParser', [])
        .config(['$interpolateProvider', function ($interpolateProvider) {
            $interpolateProvider.startSymbol('__');
            $interpolateProvider.endSymbol('__');
        }])
        .factory('EmailParser', ['$interpolate', function ($interpolate) {
            //处理解析的服务
            return {
                parse: function (text, context) {
                    var template = $interpolate(text);
                    return template(context);
                }
            }
        }]);
        angular.module('app', ['emailParser'])
        .controller('MyController', ['$scope', 'EmailParser', function ($scope, EmailParser) {
            $scope.$watch('emailBody', function (body) {
                if (body) {
                    $scope.previewText = EmailParser
                        .parse(body, { to: $scope.to });
                }
            })
        }])
    </script>
</body>
</html>
